package com.aboverock.module.system.domain;

import com.aboverock.common.enums.UserTypeEnum;
import com.aboverock.core.orm.domain.StringBaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.aboverock.module.system.constant.SystemConstants;
import com.aboverock.module.system.databind.UserDeserializer;
import com.aboverock.module.system.databind.UserTypeSerializer;
import com.aboverock.module.system.validator.constraints.UniqueLoginName;
import com.aboverock.module.system.validator.constraints.UserTypeLimit;
import com.aboverock.module.system.validator.groups.LocalUserGroup;
import com.aboverock.module.system.validator.groups.UpdateLocalUserGroup;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;

/**
 * <p>
 * 用户类.
 * </p>
 *
 * @author Rock Wang
 * @since 2018-11-07
 */
@ApiModel(value = "User对象", description = "")
@TableName("t_sys_user")
@JsonIgnoreProperties(value = { "password", "createTime", "createUser", "updateTime",
    "updateUser" }, allowSetters = true)
@JsonDeserialize(using = UserDeserializer.class)
public class User extends StringBaseEntity {

    @ApiModelProperty(value = "登录域帐号")
    @NotBlank
    @Pattern(regexp = SystemConstants.LOCAL_USER_LOGIN_NAME_REGEXP, message = "{smart.constraints.LoginName.local.user.message}", groups = LocalUserGroup.class)
    @UniqueLoginName(groups = LocalUserGroup.class)
    private String loginName;

    @ApiModelProperty(value = "姓名")
    @Length(max = 128)
    @NotBlank(groups = LocalUserGroup.class)
    private String name;

    @ApiModelProperty(value = "密码")
    @NotBlank(groups = UpdateLocalUserGroup.class)
    @Pattern(regexp = SystemConstants.PWD_REGEXP, message = "{smart.constraints.Password.local.user.message}", groups = UpdateLocalUserGroup.class)
    private String password;

    @ApiModelProperty(value = "员工编号")
    private String empNo;

    @ApiModelProperty(value = "部门编号")
    private String deptNo;

    @ApiModelProperty(value = "体系编号")
    private String bunitNo;

    @ApiModelProperty(value = "职位")
    private String title;

    @ApiModelProperty(value = "常驻工作地点名")
    private String address;

    @ApiModelProperty(value = "邮箱")
    @Email
    @NotBlank(groups = LocalUserGroup.class)
    private String email;

    @ApiModelProperty(value = "手机号")
    private String mobilephone;

    @ApiModelProperty(value = "性别 0：保密，1：男，2：女")
    private Integer sex;

    @ApiModelProperty(value = "固定电话")
    private String tel;

    @ApiModelProperty(value = "出身日期")
    private Date birthday;

    @ApiModelProperty(value = "头像")
    private String photo;

    @ApiModelProperty(value = "帐号类型 0：AD域帐号，1：本地帐号")
    @UserTypeLimit(value = UserTypeEnum.LOCAL, message = "{smart.constraints.Type.local.user.message}", groups = UpdateLocalUserGroup.class)
    private Integer type;

    @ApiModelProperty(value = "AD域帐号员工类型(1正式员工 2派遣非考勤 3派遣考勤 4实习生 5协议员工 6外包 7生态 8其他)")
    private Integer empType;

    @ApiModelProperty(value = "状态 0：正常，1：锁定")
    private Integer status;

    /** 部门. */
    @TableField(exist = false)
    private String dept;

    /** 体系. */
    @TableField(exist = false)
    private String bunit;

    @TableField(exist = false)
    private List<Role> roles;

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public String getBunit() {
        return bunit;
    }

    public void setBunit(String bunit) {
        this.bunit = bunit;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    @JsonSerialize(using = UserTypeSerializer.class)
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmpNo() {
        return empNo;
    }

    public void setEmpNo(String empNo) {
        this.empNo = empNo;
    }

    public String getDeptNo() {
        return deptNo;
    }

    public void setDeptNo(String deptNo) {
        this.deptNo = deptNo;
    }

    public String getBunitNo() {
        return bunitNo;
    }

    public void setBunitNo(String bunitNo) {
        this.bunitNo = bunitNo;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobilephone() {
        return mobilephone;
    }

    public void setMobilephone(String mobilephone) {
        this.mobilephone = mobilephone;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getEmpType() {
        return empType;
    }

    public void setEmpType(Integer empType) {
        this.empType = empType;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "User{" +
        "loginName=" + loginName +
        ", name=" + name +
        ", password=" + password +
        ", empNo=" + empNo +
        ", deptNo=" + deptNo +
        ", bunitNo=" + bunitNo +
        ", title=" + title +
        ", address=" + address +
        ", email=" + email +
        ", mobilephone=" + mobilephone +
        ", sex=" + sex +
        ", tel=" + tel +
        ", birthday=" + birthday +
        ", photo=" + photo +
        ", type=" + type +
        ", empType=" + empType +
        ", status=" + status +
        "}";
    }

}
